package com.zk.shop.servlet.order;

import com.zk.shop.entity.Order;
import com.zk.shop.entity.User;
import com.zk.shop.service.Impl.OrderServiceImpl;
import com.zk.shop.service.OrderService;
import com.zk.shop.util.JSONServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("SelMyOrderServlet")
public class SelMyOrderServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session=req.getSession();
        User user= (User) session.getAttribute("user");

        Order order = new Order(user);
        OrderService orderService = new OrderServiceImpl();
        List<Order> orderList = orderService.selOrder(order);
        JSONServlet.getJson(req, resp, orderList);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
